<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Storage;

class Feedback extends Model
{
    use HasDateTimeFormatter, SoftDeletes;


    protected $fillable = ['user_id', 'images', 'content', 'status'];

    //用户
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }


    public function getImages()
    {
        if (!$this->images) {
            return $this->images;
        }
        $images = [];
        foreach (json_decode($this->images, true) as $item) {
            $images[] = Storage::disk('public')->url($item);
        }
        return $images;
    }
}
